﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Assets.Scripts.TDuVRUI;

namespace Assets.Scripts.TDu3DWork
{
    class TDuPostActionWorker
    {
        public void onPostAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            switch( e.m_emPostAction)
            {
                case TDuPostEventArgs.POSTACTION.DIALOGURE:
                    onDialogAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.GOODS:
                    onGoodsAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.HIT:
                    onHitAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.JUDGE:
                    onJudgeAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.QUESTIONWND:
                    onQuestionAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.RAYCAST:
                    onRayCastAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.SCROLLSTEP:
                    onStepAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.TIPPICTURE:
                    onTipPictureAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.VIDEOWND:
                    onVideoAction(sender, e);
                    break;
                case TDuPostEventArgs.POSTACTION.NONE:
                    break;
                default:
                    break;
            }
        }

        //鼠标射线碰撞
        public void onRayCastAction( UnityEngine.Object sender, TDuPostEventArgs e)
        {
            Debug.Log("鼠标点击");
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition) ;            
            RaycastHit hit;
            if( Physics.Raycast(ray,out hit, Mathf.Infinity))
            {
                Debug.Log("hit object name:" + hit.collider.name);

                TDuSceneWorker worker = (TDuSceneWorker)sender;
                worker.hitVarialbeNode(hit.collider.name);
            }
        }
        ////抓取物体
        //public void onDragAction(UnityEngine.Object sender, TDuPostEventArgs e)
        //{

        //}

        //hit动作
        public void onHitAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            //TDuTriggerScript判断触发这里的动作

        }

        //step动作
        public void onStepAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            TDuSceneWorker worker = (TDuSceneWorker)sender;
            worker.scrollStepVar(e.m_varNode);
        }

        //dialog动作
        public void onDialogAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            TDuSceneWorker worker = (TDuSceneWorker)sender;

            worker.m_uiManager.createDialogDashboard(worker,e.m_varNode, worker.m_popupCanvas);
        }

        //video动作
        public void onVideoAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            TDuSceneWorker worker = (TDuSceneWorker)sender;

            worker.m_uiManager.createVideoWndDashboard(worker,e.m_varNode, worker.m_popupCanvas);
        }

        //tipPicture动作;
        public void onTipPictureAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {
            TDuSceneWorker worker = (TDuSceneWorker)sender;
            worker.m_uiManager.createTipPictureDashboard(worker, e.m_varNode, worker.m_popupCanvas);
        }
        
        //goods动作
        public void onGoodsAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {

        }

        //judge动作
        public void onJudgeAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {

        }

        //question动作
        public void onQuestionAction(UnityEngine.Object sender, TDuPostEventArgs e)
        {

        }
    }
}
